home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- * DCtxt.c: テキスト表示処理
- ******************************************************************************
- *
- *
- */
- #include <sxdef2.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <io.h>
- #include <jfctype.h>
- #include <doslib.h>
- #include <event.h> /* イベントマンを利用するときに必要 */
- #include <sxgraph.h> /* グラフ系マネージャを利用するときに必要 */
- #include <window.h> /* ウィンドウマンを利用するときに必要 */
- #include <dialog.h> /* ダイアログマンを利用するときに必要 */
- #include <task.h> /* タスクマンを利用するときに必要 */
- #include "DC.h" /* このプログラム固有のヘッダファイル */
-
- /******************************************************************************
- * drawtxt(): テキストの描画
- ******************************************************************************
- * 引数: ComVal *pcv 共通変数へのポインタ
- * int part 0:部分書きかえ
- * 1:全画面書きかえ
- */
- void drawtxt(ComVal *pcv, int part)
- {
- int i,j,jj,k,tb,vw,drawPt,end,esc;
- char buff[100];
- char buff2[100];
- char dmyfname[100];
- char *txtPt;
- int *txtNo;
- int pat1,pat2;
- int line_no;
- int cut_no;
- int cut_lno,ylen;
- int zen;
- Rect cut_rc_src;
- Rect cut_rc_dst;
- LPoint ppos;
- Region **curRgn;
- Rect rc = { 0, 0, 0, 0};
-
- rc.d.right = pcv->win_h;
- rc.d.bottom = pcv->win_v - 20;
-
- if (pcv->loadFlag == 0)
- return;
-
- GMSetGraph(&pcv->windowPtr->graph);
- GMFontKind(pcv->fontK[pcv->font]);
- GMFontSize(LONGWORD(pcv->fontS[pcv->font],pcv->fontS[pcv->font]));
- GMForeColor(pcv->fore_color);
- GMBackColor(pcv->back_color);
-
- GMSetClip(pcv->txtRgnHdl);
-
- MMHdlLock(pcv->txt); /* テキストのハンドルをロック */
- MMHdlLock(pcv->txtNo);
-
- txtPt = *(pcv->txt);
- txtNo = *(pcv->txtNo);
-
- if (part != 0) {
- if (pcv->scrollDir > 0) { /* テキストスクロール */
- GMScroll(&rc, LONGWORD(0,-pcv->fontS[pcv->font] * pcv->scrollstep), pcv->updateRgnHdl);
- end = pcv->scrollstep + 1;
- drawPt = (29 - pcv->scrollstep) * pcv->fontS[pcv->font];
- line_no = pcv->ofset + 29 - pcv->scrollstep;
- txtPt = txtPt + *(txtNo + line_no);
- } else { /* テキスト逆スクロール */
- GMScroll(&rc, LONGWORD(0, pcv->fontS[pcv->font] * pcv->scrollstep), pcv->updateRgnHdl);
- end = pcv->scrollstep + 1;
- drawPt = 0;
- line_no = pcv->ofset;
- txtPt = txtPt + *(txtNo + pcv->ofset);
- }
- } else { /* 全テキスト表示 */
- GMForeColor(pcv->back_color);
- GMFillRect(&rc);
- GMForeColor(pcv->fore_color);
- end = 30;
- drawPt = 0;
- line_no = pcv->ofset;
- txtPt = txtPt + *(txtNo + pcv->ofset);
- }
-
- for(i=0;i<end;i++) { /* テキスト描画 */
- if (pcv->Maxline < (line_no + i)) break;
- j = 0;
- jj = 0;
- vw = 0;
- pcv->pre_esc = 33;
- zen = 1;
- GMMove(LONGWORD(0,drawPt + i * pcv->fontS[pcv->font]));
- while(1) {
- if (*txtPt == 13) { /* 改行処理 */
- buff[j] = 0;
- txtPt++;
- break;
- }
-
- if (*txtPt == 10) { /* LF処理 */
- txtPt++;
- continue;
- }
-
- if (*txtPt == 9) { /* TAB処理 */
- tb = 8 - (jj % 8);
- buff[j] = 0;
- if (j > 0)
- GMDrawStrZ(buff);
- GMMoveRel(LONGWORD(tb * pcv->fontS[pcv->font] / 2, 0));
- j = 0;
- jj = jj + tb;
- txtPt++;
- zen = 0;
- continue;
- }
-
- if (*txtPt == 27) { /* esc文字属性 */
- if (*(txtPt+1) == '[') {
- buff2[0] = 0;
- esc = 0;
- txtPt++;
- txtPt++;
- while(*txtPt != 'm' && *txtPt != 'C') {
- buff2[esc++] = *(txtPt++);
- }
- if (esc != 0) {
- if (*txtPt == 'C') {
- buff2[esc] = 0;
- esc = atoi(buff2);
- GMMoveRel(LONGWORD(esc*pcv->fontS[pcv->font]/2, 0));
- txtPt++;
- j = 0;
- continue;
- }
- buff2[esc] = 0;
- esc = atoi(buff2);
- buff[j] = 0;
- GMDrawStrZ(buff);
-
- esc_mode(pcv, esc);
-
- txtPt++;
- j = 0;
- continue;
- } else {
- buff[j] = 0;
- GMDrawStrZ(buff);
-
- esc_mode(pcv, 0);
-
- txtPt++;
- j = 0;
- continue;
- }
- }
- }
-
- if (jj == 94){ /* 行の折り返し */
- if (adjust(txtPt)) {
- buff[j++] = *txtPt++;
- buff[j++] = *txtPt++;
- }
- if (*txtPt == 13)
- txtPt++;
- buff[j] = 0;
- break;
- }
- if (jj > 94) {
- buff[j] = 0;
- break;
- }
-
- pat1 = (int)*txtPt & 0xff;
- if (iskanji(pat1)) { /* 漢字 */
- buff[j++] = *txtPt++;
- buff[j++] = *txtPt++;
- jj += 2;
- continue;
- }
-
- if (*txtPt == '%') { /* %コード処理 */
- if (*(txtPt + 1) == 'V') { /* 倍角設定 */
- vw = 1;
- txtPt = txtPt + 4;
- buff[j] = 0;
- GMDrawStrZ(buff);
- j = 0;
- continue;
- }
- if ((*(txtPt + 1) == 'C') && (*(txtPt+2) != 'U')) { /* カットファイル */
- cut_no = *(txtPt+2) - '0';
- cut_lno = *(txtPt+3) - '0';
- if (*(txtPt+4)==':') {
- while(*txtPt++ != '.') {
- }
- txtPt = txtPt + 3;
- } else {
- txtPt = txtPt + 4;
- }
- if (j>0) {
- buff[j] = 0;
- GMDrawStrZ(buff);
- j = 0;
- }
-
- GMLockBits(pcv->bitsH[cut_no][pcv->depth]);
- pcv->offgraph[cut_no][pcv->depth].bmap = &(*pcv->bitsH[cut_no][pcv->depth])->bmap;
-
- cut_rc_src.d.top = cut_lno * pcv->fontS[pcv->font];
- cut_rc_src.d.right = pcv->offgraph[cut_no][pcv->depth].rect.d.right;
- if (cut_rc_src.d.top + pcv->fontS[pcv->font] > pcv->offgraph[cut_no][pcv->depth].rect.d.bottom) {
- cut_rc_src.d.bottom = pcv->offgraph[cut_no][pcv->depth].rect.d.bottom;
- ylen = cut_rc_src.d.bottom - cut_rc_src.d.top;
- } else {
- cut_rc_src.d.bottom = cut_rc_src.d.top + pcv->fontS[pcv->font];
- ylen = pcv->fontS[pcv->font];
- }
- cut_rc_src.d.left = 0;
-
- ppos = GMGetLoc();
- cut_rc_dst.d.top = LOWWORD(ppos);
- cut_rc_dst.d.right = HIWORD(ppos) + cut_rc_src.d.right;
- cut_rc_dst.d.bottom = cut_rc_dst.d.top + ylen;
- cut_rc_dst.d.left = HIWORD(ppos);
-
- GMCopy(&(*pcv->bitsH[cut_no][pcv->depth])->bmap, pcv->windowPtr->graph.bmap,
- &cut_rc_src, &cut_rc_dst,
- G_PSET, NULL); /* pcv->windowPtr->update); */
- GMUnlockBits(pcv->bitsH[cut_no][pcv->depth]);
- GMMoveRel(LONGWORD(cut_rc_src.d.right,0));
- continue;
- }
- }
-
- if (*txtPt == 24) { /* 倍角解除 */
- if (vw == 1) {
- esc_mode(pcv, 0);
- buff[j] = 0;
- GMFontKind(pcv->fontK[pcv->font] + 1);
- GMFontSize(LONGWORD(pcv->fontL[pcv->font],pcv->fontL[pcv->font]));
- GMMoveRel(LONGWORD(0,4));
- GMDrawStrZ(buff);
- GMFontKind(pcv->fontK[pcv->font]);
- GMFontSize(LONGWORD(pcv->fontS[pcv->font],pcv->fontS[pcv->font]));
- GMMoveRel(LONGWORD(0,-4));
- vw = 0;
- jj = jj + j / 2;
- if (pcv->font == 0)
- GMMove(LONGWORD(jj * pcv->fontS[pcv->font] / 2,
- drawPt + i * pcv->fontS[pcv->font]));
- j = 0;
- txtPt++;
- continue;
- }
- txtPt++;
- continue;
- }
-
- buff[j++] = *(txtPt++);
- buff[j] = 0;
-
- jj++;
- }
-
- if (vw) {
- GMFontKind(pcv->fontK[pcv->font] + 1);
- GMFontSize(LONGWORD(pcv->fontL[pcv->font],pcv->fontL[pcv->font]));
- GMMoveRel(LONGWORD(0, 4));
- }
- GMDrawStrZ(buff);
- if (vw) {
- GMFontKind(pcv->fontK[pcv->font]);
- GMFontSize(LONGWORD(pcv->fontS[pcv->font],pcv->fontS[pcv->font]));
- GMMoveRel(LONGWORD(0, -4));
- vw = 0;
- }
- pcv->pre_esc = 33;
- esc_mode(pcv, 33);
- }
- MMHdlUnlock(pcv->txtNo); /* テキストのハンドルをアンロック */
- MMHdlUnlock(pcv->txt);
- GMSetClip(pcv->winRgnHdl);
- CMValueSet(pcv->volHdl, pcv->ofset);
- if (!pcv->lineDisp) { /* 行番号表示 */
- GMShadowRect(&pcv->rcl);
- GMMove(pcv->lxy.x_y);
- sprintf(buff, "%5d", pcv->ofset + 1);
- GMFontKind(G_ROM12);
- GMFontSize(LONGWORD(12,12));
- GMDrawStrZ(buff);
- }
- }
-
- /******************************************************************************
- * esc_mode(): テキストの描画モード変更処理
- ******************************************************************************
- * 引数: ComVal *pcv 共通変数へのポインタ
- * int esc 描画モード
- */
- int esc_mode(ComVal *pcv, int esc)
- {
- int esc_color, pre_esc_color;
- int esc_mode, pre_esc_mode;
-
- GMSetGraph(&pcv->windowPtr->graph);
- if (esc == 0)
- esc = 33;
-
- pre_esc_color = (pcv->pre_esc % 10) % 4;
- pre_esc_mode = pcv->pre_esc;
- esc_color = (esc % 10) % 4;
- esc_mode = esc;
-
- if (esc == 1) {
- if (pre_esc_mode < 34)
- esc_mode = pre_esc_mode + 4;
- if (pre_esc_mode > 43)
- esc_mode = pre_esc_mode - 4;
- esc_color = pre_esc_color;
- }
- if (esc == 7) {
- if (pre_esc_mode < 38)
- esc_mode = pre_esc_mode + 10;
- if (pre_esc_mode > 39)
- esc_mode = pre_esc_mode - 10;
- esc_color = pre_esc_color;
- }
-
- switch(esc_color) {
- case 0: GMForeColor(pcv->back_color);
- break;
- case 1: GMForeColor(G_BLUE);
- break;
- case 2: GMForeColor(G_RED);
- break;
- case 3: GMForeColor(pcv->fore_color);
- break;
- }
-
- if (esc_mode < 34) {
- GMFontMode(G_PSET);
- GMFontFace(G_PLANE);
- GMFontSize(LONGWORD(pcv->fontS[pcv->font],pcv->fontS[pcv->font]));
- return (esc);
- }
- if (esc_mode < 38) {
- GMFontMode(G_PSET);
- GMFontFace(G_BOLD);
- GMFontSize(LONGWORD(pcv->fontS[pcv->font] - 1,pcv->fontS[pcv->font]));
- return (esc);
- }
- if (esc_mode < 44) {
- GMFontMode(G_NXOR);
- GMFontFace(G_PLANE);
- GMFontSize(LONGWORD(pcv->fontS[pcv->font],pcv->fontS[pcv->font]));
- return (esc);
- }
- if (esc_mode < 34) {
- GMFontMode(G_NXOR);
- GMFontFace(G_BOLD);
- GMFontSize(LONGWORD(pcv->fontS[pcv->font] - 1,pcv->fontS[pcv->font]));
- return (esc);
- }
-
- return(esc);
- }
-
- /******************************************************************************
- * scrollTxt(): テキストのスクロール処理
- ******************************************************************************
- * 引数: ComVal *pcv 共通変数へのポインタ
- * int part 1:上スクロール
- * -1:下スクロール
- */
- int scrollTxt(ComVal *pcv, int dir)
- {
- int sclbuff;
- pcv->scrollDir = dir;
-
- if (pcv->loadFlag == 0)
- return;
-
- if (dir > 0) {
- if (pcv->ofset < (pcv->Maxline - 29)) {
- pcv->ofset = pcv->ofset + pcv->scrollstep;
- drawtxt(pcv, 1); /* ウィンドウ内部を描画する */
- return (1);
- }
- } else {
- if (pcv->ofset > 0) {
- pcv->ofset = pcv->ofset - pcv->scrollstep;
- if ((pcv->ofset - pcv->scrollstep) < 0) {
- sclbuff = pcv->scrollstep;
- pcv->scrollstep = pcv->scrollstep + pcv->ofset;
- pcv->ofset = 0;
- drawtxt(pcv, 1); /* ウィンドウ内部を描画する */
- pcv->scrollstep = sclbuff;
- } else {
- drawtxt(pcv, 1); /* ウィンドウ内部を描画する */
- }
- return (1);
- }
- }
- return (0);
- }
-
- /******************************************************************************
- * adjust(): いいかげんな禁則処理
- ******************************************************************************
- * 引数: char *txtPt
- */
- int adjust(char *txtPt)
- {
- int pat, ret;
-
- pat = ((((int)*txtPt) << 8) + (int)*(txtPt+1)) & 0xffff;
- switch(pat) {
- case L'ぁ':
- case L'ぃ':
- case L'ぅ':
- case L'ぇ':
- case L'ぉ':
- case L'ァ':
- case L'ィ':
- case L'ゥ':
- case L'ェ':
- case L'ォ':
- case L'ゃ':
- case L'ゅ':
- case L'ょ':
- case L'ゎ':
- case L'っ':
- case L'ャ':
- case L'ュ':
- case L'ョ':
- case L'ヮ':
- case L'ッ':
-
- case L'、':
- case L'。':
- case L',':
- case L'.':
- case L'?':
- case L'!':
- case L'゛':
- case L'´':
- case L'`':
- case L'‘':
- case L'“':
- case L')':
- case L'〕':
- case L']':
- case L'}':
- case L'〉':
- case L'》':
- case L'」':
- case L'』':
- case L'】':
- case L'>':
- ret = 1;
- break;
- default:
- ret = 0;
- break;
- }
- return(ret);
- }
- STR@ -ム EdEV 3.00 <